In [7]:
import sys
if not '..' in sys.path:
    sys.path.insert(0, '..')
import control
import sympy
import numpy as np
import matplotlib.pyplot as plt
import ulog_tools as ut
import ulog_tools.control_opt as opt

%matplotlib inline
%load_ext autoreload
%autoreload 2


The autoreload extension is already loaded. To reload it, use:
  %reload_ext autoreload

System Identification


In [3]:
log_file = ut.ulog.download_log('http://review.px4.io/download?log=35b27fdb-6a93-427a-b634-72ab45b9609e', '/tmp')
data = ut.sysid.prepare_data(log_file)
res = ut.sysid.attitude_sysid(data)
res


Out[3]:
{'pitch': {'model': {'delay': 0.051503721021908873,
   'f_s': 232.99287433805779,
   'fit': 0.57135828183122261,
   'gain': 29.538707721830491,
   'sample_delay': 12},
  't_end': 80,
  't_start': 75},
 'roll': {'model': {'delay': 0.072963604781037569,
   'f_s': 232.99287433805779,
   'fit': 0.80970246292599435,
   'gain': 45.686710321167887,
   'sample_delay': 17},
  't_end': 105,
  't_start': 100},
 'yaw': {'model': {'delay': 0.11159139554746923,
   'f_s': 232.99287433805779,
   'fit': 0.87415539224859207,
   'gain': 41.274521147805387,
   'sample_delay': 26},
  't_end': 5,
  't_start': 0}}

Continuous Time Optimization


In [8]:
opt.attitude_loop_design(res['roll']['model'], 'ROLL', d)


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-8-2a15fca2e900> in <module>()
----> 1 opt.attitude_loop_design(res['roll']['model'], 'ROLL')

TypeError: attitude_loop_design() missing 2 required positional arguments: 'dcut_hz' and 'est_delay'

In [6]:
attitude_loop_design(res['pitch']['model'], 'PITCH')


Out[6]:
{'MC_PITCHRATE_D': 0.015662896675004697,
 'MC_PITCHRATE_I': 0.48847645640076243,
 'MC_PITCHRATE_P': 0.51104029619426683,
 'MC_PITCH_P': 5.8666514695501988}

In [7]:
attitude_loop_design(res['yaw']['model'], 'YAW')


Out[7]:
{'MC_YAWRATE_D': 0.017251069591687748,
 'MC_YAWRATE_I': 0.19498248018478978,
 'MC_YAWRATE_P': 0.18924319337905329,
 'MC_YAW_P': 3.598452484267229}